#pragma once
#include"HashTable.h"
#include<iostream>
namespace hc
{
	template<class K>
	struct HashFunc
	{
		size_t operator()(const K& key)
		{
			return size_t(key);
		}
	};
	template<>
	struct HashFunc<std::string>
	{
		size_t operator()(const std::string& str)
		{
			int hash = 0;
			for (auto e : str)
			{
				hash *= 131;
				hash += e;
			}
			return hash;
		}
	};
	template<class K,class hash=HashFunc<K>>
	class unordered_set
	{
		struct KeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename HashTable<K, const K, KeyOfT, hash>::iterator iterator;
		typedef typename HashTable<K, const K, KeyOfT, hash>::const_iterator const_iterator;
		iterator begin()
		{
			return _ht.begin();
		}
		iterator end()
		{
			return _ht.end();
		}
		const_iterator begin()const
		{
			return _ht.begin();
		}
		const_iterator end()const
		{
			return _ht.end();
		}
		std::pair<iterator, bool> insert(const K& key)
		{
			return _ht.insert(key);
		}
		bool erase(const K& key)
		{
			return _ht.Erase(key);
		}
		iterator find(const K& key)
		{
			return _ht.Find(key);
		}
	private:
		HashTable<K, const K, KeyOfT, hash> _ht;
	};
	void test_unordered_set()
	{
		unordered_set<int> s;
		s.insert(31);
		s.insert(11);
		s.insert(5);
		s.insert(15);
		s.insert(25);

		unordered_set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			//*it = 1;
			std::cout << *it << " ";
			++it;
		}
		std::cout << std::endl;

		for (auto e : s)
		{
			std::cout << e << " ";
		}
		std::cout << std::endl;
	}
}
